package o;

import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.List;

public class bmb {
    private SQLiteOpenHelper ˊ;
    private String ॱ;

    public bmb(SQLiteOpenHelper sQLiteOpenHelper, String str) {
        this.ˊ = sQLiteOpenHelper;
        this.ॱ = str;
    }

    public long ˊ(blw o_blw) {
        long j = -1;
        try {
            j = this.ˊ.getWritableDatabase().insertOrThrow(this.ॱ, null, o_blw.ˎ());
        } catch (SQLiteException e) {
            bmg.ˊ.ˏ("DBHandler", "insert ex : SQLiteException");
        } catch (IllegalStateException e2) {
            bmg.ˊ.ˏ("DBHandler", "insert ex : IllegalStateException");
        }
        return j;
    }

    private Cursor ˏ(String str, String[] strArr, String str2, String str3, String str4) {
        try {
            return this.ˊ.getWritableDatabase().query(this.ॱ, new String[]{"*"}, str, strArr, str2, str3, str4);
        } catch (SQLiteException e) {
            bmg.ˊ.ˏ("DBHandler", "query ex :SQLiteException");
            return null;
        } catch (IllegalStateException e2) {
            bmg.ˊ.ˏ("DBHandler", "query ex: IllegalStateException");
            return null;
        }
    }

    public <T extends blw> List<T> ˏ(Class<T> cls, String str) {
        return ˊ(cls, null, null, null, null, str);
    }

    public <T extends blw> List<T> ˊ(Class<T> cls, String str, String[] strArr, String str2, String str3, String str4) {
        List<T> arrayList = new ArrayList();
        Cursor ˏ = ˏ(str, strArr, str2, str3, str4);
        if (ˏ != null) {
            while (ˏ.moveToNext()) {
                try {
                    blw ॱ = bmd.ॱ(cls);
                    if (ॱ != null) {
                        ॱ.ˋ(ˏ);
                        arrayList.add(ॱ);
                    }
                } catch (Throwable th) {
                    ˊ(ˏ);
                }
            }
        }
        ˊ(ˏ);
        return arrayList;
    }

    public int ˎ(blw o_blw, String str, String[] strArr) {
        int i = 0;
        try {
            i = this.ˊ.getWritableDatabase().update(this.ॱ, o_blw.ˎ(), str, strArr);
        } catch (SQLiteException e) {
            bmg.ˊ.ˏ("DBHandler", "update ex : SQLiteException");
        } catch (IllegalStateException e2) {
            bmg.ˊ.ˏ("DBHandler", "update ex: IllegalStateException");
        }
        return i;
    }

    public int ˎ(String str, String[] strArr) {
        int i = 0;
        try {
            i = this.ˊ.getWritableDatabase().delete(this.ॱ, str, strArr);
        } catch (SQLiteException e) {
            bmg.ˊ.ˏ("DBHandler", "delete ex: SQLiteException");
        } catch (IllegalStateException e2) {
            bmg.ˊ.ˏ("DBHandler", "delete ex: IllegalStateException");
        }
        return i;
    }

    private void ˊ(Cursor cursor) {
        if (cursor != null) {
            try {
                cursor.close();
            } catch (Throwable e) {
                bmg.ˊ.ˋ("DBHandler", "closeCursor ex:", e);
            }
        }
    }
}
